package com.example.rfidserver.ticket.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.rfidserver.R;
import com.example.rfidserver.pojo.User;

import java.util.List;

public class TicketAdapter extends BaseAdapter {
    private List<User> users;
    private Context context;
    public TicketAdapter(Context context,List<User> user){
        super();
        this.users = user;
        this.context = context;
    }

    @Override
    public int getCount() {
        return users.size()==0?0:users.size();
    }

    @Override
    public User getItem(int position) {
        return users.get(position)==null?null:users.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //膨胀器?
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.item_list_ticketmanager,null);
        final TextView ticketmanager_consume_id = view.findViewById(R.id.ticketmanager_consume_id);
        final TextView ticketmanager_ticket_id = view.findViewById(R.id.ticketmanager_ticket_id);
        final TextView ticketmanager_user_id = view.findViewById(R.id.ticketmanager_user_id);
        final TextView ticketmanager_user_r_id = view.findViewById(R.id.ticketmanager_user_r_id);
        final TextView ticketmanager_integral = view.findViewById(R.id.ticketmanager_integral);
        final TextView ticketmanager_role = view.findViewById(R.id.ticketmanager_role);
        ticketmanager_consume_id.setText("消费服务项id:"+getItem(position).getConsume_id());
        ticketmanager_ticket_id.setText("门票id:"+getItem(position).getTicket_id());
        ticketmanager_user_id.setText("用户id:"+getItem(position).getId());
        System.out.println("用户id:"+getItem(position).getId());
        ticketmanager_user_r_id.setText("RFID卡id:"+getItem(position).getR_id());
        ticketmanager_integral.setText("用户积分账单:"+getItem(position).getIntegral_bill());
        //判断角色
        int role = getItem(position).getRole();
        if(role==0){
            ticketmanager_role.setText("消费者");
        }else if(role==1){
            ticketmanager_role.setText("志愿者");
        }else if(role==2){
            ticketmanager_role.setText("管理者");
        }
        return view;
    }





}
